package cn.wx.common.persistence.redisson;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import java.io.IOException;

@Configuration
public class RedissonConfig implements InitializingBean{
	
	
	@Bean(destroyMethod = "shutdown",name="redissonClient")
    public RedissonClient redisson(@Value("classpath:config/spring-redisson.yaml") Resource configFile) throws IOException {
		if(!configFile.exists()){
			return null;
		}
		Config config = Config.fromYAML(configFile.getInputStream());
        return Redisson.create(config);
    }

	
	@Override
	public void afterPropertiesSet() throws Exception {
		
	}
	
	
}
